<!--#include file="common/header.html"-->
<link rel="stylesheet" type="text/css" href="../css/autocomplete.css" media="all">
<body>
    <div class="container-fluid larry-wrapper">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <!--头部搜索-->
                <section class="panel panel-padding" style="display:none">
                    <form class="layui-form" action="/education/admin/order">
                        <input type="hidden" name="id" id="queryId">
                        <input type="hidden" name="userid">
                        <div class="layui-form">
                            <div class="layui-inline">
                                <select name="_query.type" id="orderType"
                                        data-params='{"url": "/education/admin/order"}'>
                                    <option value="">订单类别</option>
                                    <option value="1">普通订单</option>
                                    <option value="2">预购订单</option>
                                </select>
                            </div>
                            <div class="layui-inline">
                                <input class="layui-input" name="_query.startDate" placeholder="起始时间"
                                       style="width: 150px;"
                                       onclick="layui.laydate({type:'datetime', elem: this, festival:true, istime:true,
                                       max:laydate.now(), format:'YYYY-MM-DD hh:mm:ss'})">
                            </div>
                            <span style="margin-left: 5px;margin-right: 5px">至</span>
                            <div class="layui-inline">
                                <input class="layui-input" name="_query.endDate" placeholder="结束时间"
                                       style="width: 150px;"
                                       onclick="layui.laydate({type:'datetime', elem: this, festival:true, istime:true,
                                       max:laydat.now(), format:'YYYY-MM-DD hh:mm:ss'})">
                            </div>

                            <div class="layui-inline">
                                <select name="_query.status" id="orderStatus"
                                        data-params='{"url": "/education/admin/order"}'>
                                    <option value="">订单状态</option>
                                    <option value="-1">全部</option>
                                    <option value="0">待付款</option>
                                    <option value="1">待发货</option>
                                    <option value="2">已完成</option>
                                    <option value="3">已取消</option>
                                    <option value="4">待退款</option>
                                    <option value="5">待收货</option>
                                    <option value="411">备货中</option>
                                    <option value="420">已备货</option>
                                    <option value="422">待自提</option>
                                    <option value="421">已自提</option>
                                </select>
                            </div>
                           <!-- <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input class="layui-input" name="_query.keyword" placeholder="下单人">
                                </div>
                            </div>-->

                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <!--<input class="layui-input" name="_query.station_no" placeholder="自提点编号">-->
                                    <select name="_query.stationNo" id="queryStationNo" lay-search
                                            data-params='{"url": "/education/admin/order"}'>
                                        <option value="">自提点编号</option>

                                    </select>
                                </div>
                            </div>

                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input type="text" name="_query.keyword" placeholder="下单人手机号"
                                           id="autocompleteInput" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <select name="_query.level" lay-search >
                                        <option value="0">本人订单</option>
                                        <option value="1">一级下线</option>
                                        <option value="2">二级下线</option>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-inline">
                                <button lay-submit class="layui-btn" lay-filter="search">查找</button>
                            </div>
                        </div>
                    </form>
                </section>

                <!--列表-->
                <section class="panel panel-padding">
                    <div class="group-button">
                        <!--<button class="layui-btn layui-btn-small" onclick="viewDetail();">
                            <i class="iconfont">&#xe653;</i>查看
                        </button>-->
                        <button class="layui-btn layui-btn-small layui-btn-danger ajax-all" data-name="checkbox" data-params='{"url": "/education/admin/order/delete"}'>
                            <i class="iconfont">&#xe626;</i> 删除
                        </button>
                        <button class="layui-btn layui-btn-small"
                                onclick="printList();">
                            <i class="iconfont">&#xe6bc;</i>自提单打印
                        </button>
                    </div>
                    <div id="list" class="layui-form"></div>

                    <div class="text-right" id="page"></div>
                </section>
            </div>
        </div>
    </div>
    <div class="add-subcat">
        <form class="layui-form layui-form-pane" action="" id="form1">
            <input type="hidden" name="id">
            <div class="layui-form-item">
                <label class="layui-form-label">订单类别</label>
                <div>
                    <input type="radio" name="order_type" title="普通订单" value="1"/>
                    <input type="radio" name="order_type" title="预购订单" value="2"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">订单号</label>
                <div class="layui-inline">
                    <input type="text" name="order_no" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">商品金额</label>
                <div class="layui-inline" style="float: left">
                <input type="text" name="order_price" class="layui-input ">
                </div>
                <div class="layui-form-mid layui-word-aux">单位为元</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">订单总价</label>
                <div class="layui-inline" style="float: left">
                    <input type="text" name="total_amount" class="layui-input ">
                </div>
                <div class="layui-form-mid layui-word-aux">单位为元</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">运费</label>
                <div class="layui-inline" style="float: left">
                <input type="text" name="freight" class="layui-input ">
                </div>
                <div class="layui-form-mid layui-word-aux">单位为元</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">实付金额</label>
                <div class="layui-inline" style="float: left">
                <input type="text" name="pay_amount" class="layui-input ">
                </div>
                <div class="layui-form-mid layui-word-aux">单位为元</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">支付方式</label>
                <div class="layui-inline">
                    <input type="radio" name="pay_type" title="余额" value="ye"/>
                    <input type="radio" name="pay_type" title="支付宝" value="zfb"/>
                    <input type="radio" name="pay_type" title="微信" value="wx"/>
                    <input type="radio" name="pay_type" title="小程序微信" value="xcx"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">发货时间</label>
                <div class="layui-inline">
                    <input type="text" name="deliver_time" class="layui-input ">
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea name="order_memo" class="layui-textarea"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">收货地址</label>
                <div class="layui-input-block">
                    <input type="text" name="order_address" class="layui-input" id="orderAddress">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">下单人</label>
                <div class="layui-input-block">
                    <input type="text" name="order_userid" class="layui-input">
                </div>
            </div>
            <!--<div class="layui-form-item">
                <label class="layui-form-label" style="width:200px">封面图片</label>
                <div class="layui-input-block">
                    <input type="file" name="file" class="layui-upload-file" id="img">
                    <input type="hidden" name="img">
                </div>
                <div class="layui-input-inline"><div class="imgbox" style="width: 800px;"></div></div>
            </div>-->


            <div class="layui-form-item">
                <label class="layui-form-label">下单时间</label>
                <div class="layui-input-block">
                    <input type="text" name="create_time"
                           class="layui-input ">
                </div>
            </div>

         <!--   <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" jq-submit jq-filter="submit">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>-->
        </form>
    </div>
    <!--#include file="order-operate.html"-->

</body>
<!--#include file="order-list.html"-->
<script src="../js/layui/layui.js"></script>
<script type="text/javascript" src="../js/lib/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../js/lib/rest.js"></script>
<script type="text/javascript" src="../js/lib/bootstrap.autocomplete.js"></script>
<!--#include file="common/version.html"-->
<script>
    layui.use('user_list');

    /*
    订单详情查看
     */
    function viewDetail(ids){
        $('.imgbox').children().remove();
        $('input,select,textarea','#form1').attr('readonly',true);
        $("input:radio").attr("disabled","disabled");
        restGet('/education/admin/order/view/' + ids, null, $('#form1'), function(rs){
            if(rs.status == 200){
                var data = rs.data.order_address;
                var str =  '<img src="/education{src}" alt="..." class="img-thumbnail">';
                //var imgDiv = $('input[name=img]').parent().next().children('.imgbox');
                $('.imgbox').append(str.replace('{src}', rs.data.img));
                $('.layui-form-radio').not('.layui-form-radioed').remove();

                var add = (data.province||'' )+ (data.city||'') +
                    (data.district||'') + (data.street||'') + (data.detail||'');
                $('#orderAddress').val(add);
                var index = layer.open({
                    type: 1,
                    title:'查看',
                    content: $('.add-subcat')
                });
                layer.full(index);
            }
        })
    }


    function viewItem(ids, no, amount, price, freight) {
        // var ids = item.id, ono = item.order_no;
        var title = "订单【{x}】明细，订单总价：{a}元（商品价：{b}元，运费：{c}元） ";
        title = title.replace('{x}', no).replace('{a}', amount).replace('{b}', price).replace('{c}', freight);
        var index = layer.open({
            type: 2,
            content: "orderItem.html?orderId="+ ids, "title": title, "area": ['500px', '400px'],
            "maxmin":"true"
        });
        layer.full(index);
    }

    function send(ids, no, status) {
        var title = "订单【"+ no +"】";
        var index;
        if(status == 411) {
            layer.confirm('确认 <span style="color:red">备货</span> 操作吗?',  {icon: 3, title:'提示'}, function(index){
                restPost('/education/admin/order/send/' + ids, {'id': ids}, function(rs){
                    if(rs.status == 200){
                        location.reload();
                    } else {
                        layer.msg(rs.msg);
                    }
                });
                layer.close(index);
            });
        } else {
            $('#sendOrderId').val(ids);
            index = layer.open({
                type: 1,area:'500px',
                title: title + '发货',
                content: $('.send-subcat')
            });
        }
    }

    function refund(id, no) {
        //退款人，退款理由，是否同意退款
        restGet('/education/admin/orderFlow/viewRefund/' + id, null, $('#form_refund'), function(rs){
            var index =  layer.open({
                type: 1,
                content: $('.refund-subcat'), "title": "订单【{no}】退款".replace('{no}', no),
                area: '500px',
                "maxmin":"true"
            });
        });
    }

    function initData(){
        var arr = ['<option value="">请选择</option>'];
        restPost('/education/api/dict', {'type':'deliver.company'}, function(rs){
            if(rs.code == 200){
                for(var $i=0; $i< rs.data.length; $i++){
                    var d = rs.data[$i];
                    arr.push('<option value="{v}">{n}</option>'.replace('{v}', d['value']).replace('{n}', d['value']));
                }
                $('#express').html(arr.join(''));
            }
        });
        arr = ['<option value=" ">自提点列表</option>'];
        restPost('/education/admin/station', {'pageSize':200}, function(rs){
            if(rs.status == 200){
                for(var $i=0; $i< rs.data.list.length; $i++){
                    var d = rs.data.list[$i];
                    arr.push('<option value="{v}">{n}</option>'.replace('{v}', d['station_no'])
                        .replace('{n}', d['station_name']));
                }
                $('#queryStationNo').html(arr.join(''));
            }
        });
        var uid = getQueryString('orderId') || '';
        var $v = '{"url":"/education/admin/order?id=' + uid
            + '","dataName":"orderData","pageid":"#page", "method":"post", "data":""}';
        $("#list-tpl").attr('data-params', $v);
        $('#queryId').val(uid);
        if(uid){
            $('#autocompleteInput').parent().hide();
        }
    }

    $(function(){
        //$('# autocompleteInput').parent().parent().hide();
        $('#autocompleteInput').autocomplete({
            source:function(query,process){
                var matchCount = this.options.items;//返回结果集最大数量
                $.post("/education/admin/user/query",{"keyword":query, },function(respData){
                    console.log(respData);
                    if(respData.code == 200) {
                        return process(respData.data);
                    }
                });
            },
            formatItem:function(item){
                var name = item["name"] || '';
                var username = item["username"] || '';
                return name +"("+ username + ")";
            },
            setValue:function(item){
                return {'data-value':item["username"],'real-value':item["username"]+'-'+item["id"]};
            }
        });
    });

    function printList() {
        var checked = $("input[name=checkbox]:checked");
        if (checked.length < 1) {
            layer.msg('请选择一项待修改的数据');
            return;
        }
        console.log(checked)
        var arr = [];
        $.each(checked, function (i, n) {
            arr.push($(n).val());
        });
        console.log(arr);
        window.open('/education/admin/order/printList?ids='+arr.join(','));
    }
</script>

</html>